//
//  TMGProductTableViewCell.m
//  TMGold
//
//  Created by Mac on 2017/11/9.
//  Copyright © 2017年 tangmu. All rights reserved.
//

#import "TMGProductTableViewCell.h"
#define monthColor  [UIColor colorWithRed:62/255.0 green:130/255.0 blue:277.0/255.0 alpha:1]
@interface TMGProductTableViewCell()
@property(nonatomic, strong) STButton                     *titleButton;
@property(nonatomic, strong) STLabel                     *yearPecetLabel;
@property(nonatomic, strong) STLabel                     *timeLabel;
@property(nonatomic, strong) STLabel                     *moneyLabel;
@property(nonatomic, strong) UIImageView                     *bannerimageView;/**< xiugai  */
@end
@implementation TMGProductTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self == [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self configSubView];
    }
    return self;
}
+ (CGFloat)cellHeight{
    //修改为87
    return 87;
    return 125;
}
#pragma mark --subView
- (void)configSubView{

    self.backgroundColor = [UIColor whiteColor];
    
    self.titleButton = [[STButton alloc] initWithFrame:CGRectMake(10, 0, 200, 44)
                                                 title:@"流动金"
                                            titleColor:FirstTextColor
                                             titleFont:14
                                          cornerRadius:0
                                       backgroundColor:nil
                                       backgroundImage:nil
                                                 image:nil];
    self.titleButton.titleEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 0);
    [self addSubview:self.titleButton];
    self.titleButton.centerY = 22;
    
    STButton * iconButton = [[STButton alloc] initWithFrame:CGRectMake(0, 0, 44, 44)
                                                      title:nil
                                                 titleColor:nil
                                                  titleFont:0
                                               cornerRadius:0
                                            backgroundColor:nil
                                            backgroundImage:nil
                                                      image:[UIImage imageNamed:@"sy_箭头02"]];
    [self addSubview:iconButton];
    iconButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
    iconButton.right = UIScreenWidth - 15;
    
    UIView * line = [[UIView alloc] initWithFrame:CGRectMake(10, iconButton.bottom, UIScreenWidth - 20, 0.5)];
    line.backgroundColor = TM_lineColor;
    [self addSubview:line];
    
    
    self.yearPecetLabel = [[STLabel alloc] initWithFrame:CGRectMake(10, line.bottom  +10 , UIScreenWidth/2, 30)
                                                    text:@"7~8%"
                                               textColor:TM_orangeColor
                                                    font:22
                                             isSizetoFit:NO
                                           textAlignment:NSTextAlignmentLeft];
    [self addSubview:self.yearPecetLabel];
    
    self.timeLabel = [[STLabel alloc] initWithFrame:CGRectMake(self.yearPecetLabel.right, self.titleButton.bottom , UIScreenWidth/2, 30)
                                                    text:@"买入期限 6~345天"
                                               textColor:TM_firstTextColor
                                                    font:14
                                             isSizetoFit:NO
                                           textAlignment:NSTextAlignmentRight];
    self.timeLabel.attributedText = [self.timeLabel.text st_convertAttributeStringWithKeyWord:@"买入期限" attributes:@{NSForegroundColorAttributeName:TM_secendTextColor}];
     self.timeLabel.right = UIScreenWidth - 15;
    [self addSubview:self.timeLabel];

    STLabel * yearLable = [[STLabel alloc] initWithFrame:CGRectMake(10, self.yearPecetLabel.bottom, UIScreenWidth / 2, 16)
                                                    text:@"预期黄金收益率"
                                               textColor:TM_secendTextColor
                                                    font:14
                                             isSizetoFit:NO
                                           textAlignment:NSTextAlignmentLeft];
   
    [self addSubview:yearLable];
    
    self.moneyLabel = [[STLabel alloc] initWithFrame:CGRectMake(self.yearPecetLabel.right, self.yearPecetLabel.bottom, UIScreenWidth / 2, 16)
                                                    text:@"起购金额  1元起投"
                                               textColor:TM_firstTextColor
                                                    font:14
                                             isSizetoFit:NO
                                           textAlignment:NSTextAlignmentRight];
    self.moneyLabel.attributedText = [self.moneyLabel.text st_convertAttributeStringWithKeyWord:@"起购金额" attributes:@{NSForegroundColorAttributeName:TM_secendTextColor}];
      self.moneyLabel.right = UIScreenWidth - 15;
    [self addSubview:self.moneyLabel];
    

    UIView * grawView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 10)];
    grawView.backgroundColor = TM_backgroundColor;
    grawView.bottom = 125;
    //[self addSubview:grawView];
    
    //修改产品样式 5、3
    for (UIView * view in self.subviews) {
        [view removeFromSuperview];
    }
    self.bannerimageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, self.class.cellHeight - 20)];
    [self addSubview:self.bannerimageView];
    UIView * whiteView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 20)];
    whiteView.backgroundColor = TM_backgroundColor;
    whiteView.bottom = self.class.cellHeight;
    [self addSubview:whiteView];
}
- (void)setModel:(TMHomeCellModel *)model{
    _model = model;

    [self.titleButton setTitle:model.name forState:UIControlStateNormal];
    self.moneyLabel.text = [NSString stringWithFormat:@"起购金额    %@元起购",@(model.buy_start.integerValue)];
    self.moneyLabel.attributedText = [self.moneyLabel.text st_convertAttributeStringWithKeyWord:@"起购金额" attributes:@{NSForegroundColorAttributeName:TM_secendTextColor}];
    NSString * rate = self.model.rate_from;
    if (self.model.rate_to.floatValue > 0.1) {
        rate = [NSString stringWithFormat:@"%@~%@",self.model.rate_from,self.model.rate_to];
    }
    rate = [NSString stringWithFormat:@"%@%%",rate];
    self.yearPecetLabel.text = rate;
    
    if (model.productID.integerValue == 6) {
        self.timeLabel.text = [NSString stringWithFormat:@"买入期限  %@~%@月",model.date_from,model.date_to];
         //[self.titleButton setTitleColor:monthColor forState:UIControlStateNormal];
    }else{
       self.timeLabel.text = [NSString stringWithFormat:@"买入期限  %@~%@天",model.date_from,model.date_to];
        // [self.titleButton setTitleColor:TM_orangeColor forState:UIControlStateNormal];
    }
    if (!model.date_to && !model.date_from) {
        self.timeLabel.text = [NSString stringWithFormat:@"买入期限  %@",@"随时买卖"];
    }
    
    
    if (self.model.productID.integerValue == 2 || self.model.productID.integerValue == 3) {
        self.yearPecetLabel.textColor = TM_orangeColor;
    }else{
        self.yearPecetLabel.textColor = monthColor;
    }

    if (model.indexPath.row == 0) {
        self.bannerimageView.image = [UIImage imageNamed:@"组2"];
    }
    
    if (model.indexPath.row == 1) {
        self.bannerimageView.image = [UIImage imageNamed:@"组1"];
    }
}
@end
